package com.health.agent.server.config;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.health.common.domain.PmsMedic;
import com.health.common.redis.service.RedisService;
import com.health.health.common.dto.PmsConsultationRecordDto;
import com.health.income.remote.feign.RemoteIncomeService;
import com.health.patient.remote.PatientRemoteService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Description;
import org.springframework.core.NestedExceptionUtils;

import java.math.BigDecimal;
import java.util.List;
import java.util.function.Function;

/**
 * @author liu
 * @date 2025/03/02 14:04
 **/
@Configuration
public class AiFunctionCallConfig {
    private static final Logger logger = LoggerFactory.getLogger(AiFunctionCallConfig.class);


    @Autowired
    private RedisService redisService;
    @Autowired
    private PatientRemoteService patientRemoteService;
    @Autowired
    private RemoteIncomeService incomeService;

    public record GetDoctorRequest(String symptomTagsName) {}

    public record CancelRegisterRequest(String doctorName,String patientName) {}

    public record RegisterRequest(String doctorName,String patientName) {}

    @JsonInclude(JsonInclude.Include.NON_NULL)
    public record DoctorVO(Long id,String doctorName,String doctorUri,String excel,Integer doctorStatus,
      BigDecimal registrationFee) {
    }



    @Bean
    @Description("根据医生姓名挂号")
    public Function<RegisterRequest, String> doRegister() {
        System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!**************************");
        return request -> {
            try {
                PmsConsultationRecordDto recordDto = new PmsConsultationRecordDto();
                recordDto.setConsultationType(1);
                //redisService.get
                recordDto.setDoctorId(1L);
                recordDto.setPatientId(2L);
                patientRemoteService.addConsultation(recordDto);
                return "成功";
            }
            catch (Exception e) {
                logger.warn("Do Register: {}", NestedExceptionUtils.getMostSpecificCause(e).getMessage());
                return "失败";
            }
        };
    }


    @Bean
    @Description("根据病状查询医生")
    public Function<GetDoctorRequest, List<PmsMedic>> getMedicList() {
        return new Function<GetDoctorRequest, List<PmsMedic>>() {
            @Override
            public List<PmsMedic> apply(GetDoctorRequest getDoctorRequest) {
                PmsMedic pmsMedic = new PmsMedic();
                pmsMedic.setSymptomTagsName(getDoctorRequest.symptomTagsName);
                List<PmsMedic> medicList = incomeService.getMedicList(pmsMedic).getData();
                System.out.println(medicList.toString());
                return medicList;
            }
        };
    }









    //    @Bean
//    @Description("根据医生姓名取消挂号")
//    public Function<CancelRegisterRequest, String> cancelRegister() {
//        return request -> {
//            try {
//                doctorRemote.cancelRegister(request.doctorName(),request.patientName);
//                return "成功";
//            }
//            catch (Exception e) {
//                logger.warn("cancel Register: {}", NestedExceptionUtils.getMostSpecificCause(e).getMessage());
//                return "失败";
//            }
//        };
//    }
//
}
